package com.ok.user.controller;


import com.ok.common.domain.po.Result;
import com.ok.user.domain.po.OkAdmin;
import com.ok.user.service.IOkAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 管理员 前端控制器
 * </p>
 *
 * @author lhw
 * @since 2024-05-06
 */
@Slf4j
@Api(tags = "管理员相关接口")
@RestController
@RequestMapping("/admin")
@RequiredArgsConstructor
public class OkAdminController {

    private final IOkAdminService okAdminService;

    @ApiOperation(value = "管理员登录")
    @PostMapping("/login")
    public Result login(@RequestBody OkAdmin admin){
        String jwt =okAdminService.login(admin);
        log.info("jwt:{}",jwt);
        return Result.success(jwt);
    }

    @ApiOperation(value = "管理员注册")
    @PostMapping("/register")
    public Result register(@RequestBody OkAdmin admin){
        //密码加密
        admin.setPassword(DigestUtils.md5DigestAsHex(admin.getPassword().getBytes()));
        okAdminService.save(admin);
        return Result.success("注册成功");
    }

}
